package com.shiyang.prototype.deepclone;

/**
 * @author shiyang date: 2020/9/9
 */
public class Client {
    public static void main(String[] args) throws CloneNotSupportedException {
        DeepProtoType deepProtoType = new DeepProtoType();
        deepProtoType.setName("tom");
        deepProtoType.setDeepCloneableTarget(new DeepCloneableTarget("jack", "tom's friend"));

        // 深拷贝 : 方式一
        DeepProtoType clone1 = deepProtoType.clone();
        DeepProtoType clone2 = deepProtoType.clone();
        DeepProtoType clone3 = deepProtoType.clone();
        System.out.println(deepProtoType);
        System.out.println(clone1);
        System.out.println(clone2);
        System.out.println(clone3);
        /* 
        * 各个deepCloneableTarget实力都不一样
        * DeepProtoType{name='tom', deepCloneableTarget=com.shiyang.prototype.deepclone.DeepCloneableTarget@1540e19d}
        * DeepProtoType{name='tom', deepCloneableTarget=com.shiyang.prototype.deepclone.DeepCloneableTarget@677327b6}
        * DeepProtoType{name='tom', deepCloneableTarget=com.shiyang.prototype.deepclone.DeepCloneableTarget@14ae5a5}
        * DeepProtoType{name='tom', deepCloneableTarget=com.shiyang.prototype.deepclone.DeepCloneableTarget@7f31245a}
        * */

        // 深拷贝 - 方式二
        DeepProtoType clone4 = deepProtoType.deepClone();
        System.out.println(clone4);
        // DeepProtoType{name='tom', deepCloneableTarget=com.shiyang.prototype.deepclone.DeepCloneableTarget@6acbcfc0}
    }
}
